package com.grape.dp.observer.spring.event.listener;

import cn.hutool.json.JSONUtil;
import com.grape.dp.observer.spring.event.OrderMessageEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 描述:EmailListener
 * @author: myx
 * @date: 2019/7/29 0029
 * Copyright © 2019-grape. All rights reserved.
 */
@Component
public class EmailListener implements ApplicationListener<OrderMessageEvent> {
    @Override
    @Async
    public void onApplicationEvent(OrderMessageEvent event) {
        //如何获取到当前容器下面所有的观察者呢？反射机制获取ApplicationListener 接口下面子类
        System.out.println(Thread.currentThread().getName()+"开始发送邮件消息内容:" + JSONUtil.toJsonStr(event.getJsonObject()));
    }
}

